/*******************************************************************************
 * Copyright (c) 2001, 2002 Boris Pruessmann and others.
 * All rights reserved.   This program and the accompanying materials
 * are made available under the terms of the Common Public License v0.5
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/cpl-v05.html
 * 
 * Contributors:
 *    Boris Pruessmann - Initial implementation.
 ******************************************************************************/
package net.sourceforge.perforce.ui.model;

import net.sourceforge.perforce.core.api.IPerforceServer;
import net.sourceforge.perforce.core.resources.IP4File;
import net.sourceforge.perforce.core.resources.RemoteFile;
import net.sourceforge.perforce.core.resources.RemoteFolder;
import net.sourceforge.perforce.ui.internal.model.P4FileElement;
import org.eclipse.core.runtime.IAdapterFactory;
import org.eclipse.ui.IActionFilter;
import org.eclipse.ui.model.IWorkbenchAdapter;

/**
  * @version $Revision: 175 $
  * @author  <a href="mailto:bpruessmann@users.sourceforge.net">Boris Pruessmann</a>
  */
public class PerforceAdapterFactory implements IAdapterFactory
{
	// --------------------------------------------------------------------------- Private Variables
	
	private Object serverAdapter = new PerforceServerElement();
	private Object folderAdapter = new RemoteFolderElement();
	private Object fileAdapter = new RemoteFileElement();	
	private Object p4FileAdapter = new P4FileElement();

	// ------------------------------------------------------------------------------ Public Methods

	/** @see IAdapterFactory#getAdapter(Object, Class) */
	public Object getAdapter(Object adaptableObject, Class adapterType)
	{
		if (adapterType == IWorkbenchAdapter.class)
		{
			if (adaptableObject instanceof IPerforceServer)
			{
				return serverAdapter;
			}
			else
			if (adaptableObject instanceof RemoteFolder)
			{
				return folderAdapter;
			}
			else
			if (adaptableObject instanceof RemoteFile)
			{
				return fileAdapter;
			}
			else
			if (adaptableObject instanceof IP4File)
			{
				return p4FileAdapter;
			}
		}
		else
		if (adapterType == IActionFilter.class)
		{
			if (adaptableObject instanceof IP4File)
			{
				return p4FileAdapter;
			}
		}
		
		return null;
	}

	/** @see IAdapterFactory#getAdapterList() */
	public Class[] getAdapterList()
	{
		return new Class[] { IWorkbenchAdapter.class, IActionFilter.class };
	}
}
